package ui;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.studyAndroid.R;
import domain.LeftDomain;

import java.util.List;

/**
 * note:抽屉效果适配器
 * User: Shaxj
 * Date: 15-6-24
 * Time: 上午10:49
 */
public class MainLeftAdapter extends BaseAdapter {
    private Context context;
    private LayoutInflater layoutInflater;
    private List<LeftDomain> leftDomains;

    public MainLeftAdapter(Context context, List<LeftDomain> leftDomains) {
        this.layoutInflater = LayoutInflater.from(context);
        this.leftDomains = leftDomains;
        this.context = context;
        notifyDataSetChanged();
    }

    /**
     * How many items are in the data set represented by this Adapter.
     *
     * @return Count of items.
     */
    @Override
    public int getCount() {
        if (null != leftDomains) {
            return leftDomains.size();
        }
        return 0;
    }


    @Override
    public Object getItem(int position) {
        if (null != leftDomains) {
            return leftDomains.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (null == convertView) {
            convertView = layoutInflater.inflate(R.layout.indexleft_item, parent, false);
            Holder holder = new Holder();
//
            holder.imageView = (ImageView) convertView.findViewById(R.id.imageView);
            holder.textView = (TextView) convertView.findViewById(R.id.textView);
            convertView.setTag(holder);
        }

        Holder holder = (Holder) convertView.getTag();
        holder.imageView.setImageResource(leftDomains.get(position).getResourceId());
        holder.textView.setText(leftDomains.get(position).getEventWord());
        return convertView;
    }

    class Holder {
        ImageView imageView;
        TextView textView;
    }
}
